package edu.ynmd.helloworld.action;

import edu.ynmd.helloworld.vo.FormVo;
import edu.ynmd.helloworld.vo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.Format;
import java.util.Date;


@Controller
public class PublicAction {




    @RequestMapping("getStr")
    @ResponseBody
    public String  getStr() throws Exception{
        return "你好 spring boot";
    }


    @GetMapping("getNumber")
    @ResponseBody
    public int getNumber() throws  Exception{
        return 100;
    }

    @GetMapping("getBoolean")
    @ResponseBody
    public boolean getBoolean() throws  Exception{
        return true;
    }

    @GetMapping("getDate")
    @ResponseBody
    public Date getDate() throws Exception{
        return new Date();
    }


    @PostMapping("BMI")
    @ResponseBody
    public Result bMI(@RequestBody FormVo formVo) throws Exception{
        float sgf = Float.valueOf(formVo.getSg());
        float tzf = Float.valueOf(formVo.getTz());
        float result = 0.0f;
        result = tzf/(sgf*sgf);


        String resultstr="";

        if (result<18.5){
            resultstr="过轻";
        }
        else if (result>=18.5&&result<=23.9){
            resultstr="正常";
        }
        else if (result>24&&result<=27){
            resultstr="过重";
        }
        else if (result>=28&&result<=32){
            resultstr="肥胖";
        }
        else {
            resultstr="非常肥胖";
        }

        String suggest="";
        switch (resultstr){

            case "过轻":
            suggest="你一定要多吃饭饭哦";
            break;

            case "正常":
            suggest="继续保持，加油哦";
            break;

            case "过重":
            suggest="少吃点，别担心";
            break;

            case "肥胖":
            suggest="不要吃肉了，你已经不是以前的你";
            break;

            case "非常肥胖":
            suggest="不要在吃了，不然你要胖死了..";
            break;
        }

        Result ro = new Result();
        ro.setResult(result);
        ro.setResultstr(resultstr);
        ro.setSuggest(suggest);
        return ro;
    }
}
